package com.demo2do.fms.admin.dao.report;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.report.DriverCostAppointment;

/**
 *
 * @author Ark
 *
 */
@Dao("hibernate")
public interface DriverCostAppointmentDao {

    /**
     * count appointment by orgIds
     * 
     * @param orgIds
     * @return
     */
    @Query("SELECT COUNT(*) FROM DriverCostAppointment WHERE disabled = false AND organizationId IN(:orgIds)")
    public int count(@Variable("orgIds") List<Long> orgIds);
    
    /**
     * count appointment by orgId and date
     * 
     * @param organizationId
     * @param createDate
     * @return
     */
    @Query("SELECT COUNT(*) FROM DriverCostAppointment WHERE disabled = false AND organizationId = :organizationId AND status != 'REJECTED' AND TO_CHAR(createTime, 'yyyy-MM-dd') = :createDate")
    public int count(@Variable("organizationId") Long organizationId, @Variable("createDate") String createDate);
    
    /**
     * list appointment by orgIds
     * 
     * @param orgIds
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM DriverCostAppointment WHERE disabled = false AND organizationId IN(:orgIds) ORDER BY createTime DESC")
    public List<DriverCostAppointment> list(@Variable("orgIds") List<Long> orgIds, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
}
